import uiautomator2 as u2

from game import game_京东互动游戏, game_京东家居馆
from zz import zz_log, zz_code, zz_str
import sys
import traceback

log = zz_log.of()


def main():
    arguments = sys.argv[1:]
    d = u2.connect(zz_code.env('DEVICE_ID'))

    game01 = game_京东家居馆.Game(d)
    game00 = game_京东互动游戏.Game(d)
    game00.set_game_jiajv(game01)
    while True:
        game00.log_msg("关闭京东")
        game00.d.app_stop("com.jingdong.app.mall")
        try:
            ok = game00.handle_main()
            if not ok:
                break
        except Exception as ex:
            errmsg = str(ex)  # 异常重新继续执行
            log.error(errmsg)
            traceback.print_exc()


if __name__ == '__main__':
    main()
